package com.atguigu.tingshu.album.receiver;

import com.alibaba.fastjson.JSON;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.vo.album.TrackStatMqVo;
import com.tencentcloudapi.ame.v20190916.models.Album;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AlbumReceiver {

    @Autowired
    private AlbumInfoService albumInfoService;

    @KafkaListener(topics = KafkaConstant.QUEUE_TRACK_STAT_UPDATE)
    public void updateTrackStat(ConsumerRecord<String, String> record){
        try {
            String value = record.value();
            TrackStatMqVo trackStatMqVo = JSON.parseObject(value, TrackStatMqVo.class);
            log.info("[专辑服务]，监听到更新声音统计消息：{}", value);
            albumInfoService.updateTrackStat(trackStatMqVo);
        }catch (Exception e){
            log.error("[专辑服务]发生异常，异常消息：{}",e.getMessage());
        }
    }
}









